package cool.tianyou.blue.bird.common.util;

import cool.tianyou.blue.bird.common.model.entity.RestApiResult;
import org.springframework.http.ResponseEntity;

/**
 * Rest API 统一返回结果<br>
 * 注：如构建错误返回结果，则根据接口错误类型抛出指定的异常即可
 *
 * @author likeguo
 */
public class RestResultUtil {

    private RestResultUtil(){

    }

    /**
     * null body rest ok response build
     *
     * @return ResponseEntity
     */
    public static ResponseEntity<RestApiResult<Object>> ok() {
        return ResponseEntity.ok(RestApiResult.success(null));
    }

    /**
     * rest ok response build
     *
     * @param body body
     * @param <T>  result body type
     * @return ResponseEntity
     */
    public static <T> ResponseEntity<RestApiResult<T>> ok(T body) {
        return ResponseEntity.ok(RestApiResult.success(body));
    }

    /**
     * rest ok response build
     *
     * @param body    body
     * @param message success message
     * @param <T>     result body type
     * @return ResponseEntity
     */
    public static <T> ResponseEntity<RestApiResult<T>> ok(T body, String message) {
        return ResponseEntity.ok(RestApiResult.success(body, message));
    }
}
